﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class Branches : _Branches
    {
        public const string CURRENT_BRANCH_ID = "CURRENT_BRANCH_ID";
        public const string CURRENT_BRANCH = "CURRENT_BRANCH";

        public static int CurrentBranchID
        {
            get { return CurrentBranch.ID; }
        }

        public static Branches CurrentBranch
        {
            get 
            {
                return (Branches)HttpContext.Current.Session[CURRENT_BRANCH]; 
            }
            set { HttpContext.Current.Session[CURRENT_BRANCH] = value; }
        }

        public static Branches GetHeadQuarter()
        {
            Branches branch = new Branches();
            branch.Where.IsHeadQuarter.Value = true;
            branch.Query.Load();

            return branch;
        }

        public static Branches GetAllBranches()
        {
            Branches branch = new Branches();
            branch.Where.Deleted.Value = false;
            branch.Query.Load();

            return branch;
        }

        public static void DeleteBranchesByIds(string ids)
        {
            Branches branch = new Branches();
            branch.Where.Deleted.Value = false;
            branch.Where.ID.Value = ids;
            branch.Where.ID.Operator = MyGeneration.dOOdads.WhereParameter.Operand.In;
            branch.Query.Load();

            for (int i = 0; i < branch.RowCount; i++)
            {
                branch.Deleted = true;
                branch.MoveNext();
            }

            branch.Save();
        }
    }
}
